import 'package:flutter/material.dart';
import '../repository/order_repository.dart';
import '../repository/post_repository.dart';
import '../repository/user_repository.dart';
import '../tabs/OrderTab.dart';
import '../tabs/PostTab.dart';
import '../tabs/UserTab.dart';

class HomeScreen extends StatefulWidget {
  const HomeScreen({super.key});

  @override
  State<HomeScreen> createState() => _HomeScreenState();


}

class _HomeScreenState extends State<HomeScreen> {
  int _currentIndex = 0;

  final UserRepository _userRepo = UserRepository();
  final PostRepository _productRepo = PostRepository();
  final OrderRepository _orderRepo = OrderRepository();


  @override
  Widget build(BuildContext context) {
    final List<Widget> _tabs = [
      UserTab(userRepo: _userRepo),
      PostTab(postRepo: _productRepo),
      OrderTab(repository: _orderRepo, userId:  "123"),
    ];

    return Scaffold(
      appBar: AppBar(
        title: const Text('多类型数据示例 App'),
      ),
      body: _tabs[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex,
        items: const[
          BottomNavigationBarItem(icon: Icon(Icons.people), label: '用户'),
          BottomNavigationBarItem(
              icon: Icon(Icons.shopping_cart), label: '产品'),
          BottomNavigationBarItem(icon: Icon(Icons.receipt), label: '订单'),
        ],
        onTap: (index) {
          setState(() => _currentIndex = index);
        },
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () => _showSnackBar(context),
        child: const Icon(Icons.add),
      ),
    );
  }
}

void _showSnackBar(BuildContext context) {
  ScaffoldMessenger.of(context).showSnackBar(SnackBar(
    content: const Text('Action completed!'),
    action: SnackBarAction(
      label: 'OK',
      onPressed: () {},
    ),
  ));
}
